<template>
  <el-radio-group v-model="radio" @change="setValue">
    <el-radio v-for="(item,index) in options" :key="index" :label="item[valueKey]">{{ item[labelKey] }}</el-radio>
  </el-radio-group>
</template>

<script>
import { postHandle } from '@/api'

export default {
  name: 'WiseRadio',
  props: {
    value: {
      type: [String, Number, Boolean]
    },
    labelKey: {
      type: String,
      default: 'label'
    },
    valueKey: {
      type: String,
      default: 'value'
    },
    params: {
      type: Object
    },
    url: {
      type: String,
      default: ''
    },
    dataDic: {
      type: String
    }
  },
  data() {
    return {
      radio: null,
      options: []
    }
  },
  watch: {
    value(val) {
      this.radio = val
    }
  },
  mounted() {
    this.getOptions()
  },
  methods: {
    getOptions() {
      if (this.dataDic) {
        this.options = require('../data/dataDictionary')[this.dataDic]
      } else {
        this.getOptionsByUrl()
      }
    },
    getOptionsByUrl() {
      if (this.url) {
        postHandle(this.url, this.params).then(response => {
          
        })
      }
    },
    setValue(value) {
      this.$emit('input', value)
    }
  }
}
</script>

<style scoped>

</style>
